package com.gym.code.generator.impl.bean;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.apache.commons.collections.CollectionUtils;

import com.gym.code.generator.AbstractContentGenerator;
import com.gym.code.generator.model.mapping.bean.BeanGenerateModel;
import com.gym.code.generator.model.mapping.bean.EnumGenerateModel;
import com.gym.code.generator.model.mapping.field.EnumFieldGenerateModel;
import com.gym.code.generator.model.mapping.field.FieldGenerateModel;

/**
 * 
 * @author xinchun.wang 
   @email: 532002108@qq.com
 * @createTime 2015-5-23 下午6:38:37
 */
public abstract class AbstractBeanGenerator extends AbstractContentGenerator<BeanGenerateModel> {
	
	@Override
	protected List<String> generateFields(BeanGenerateModel bean) {
		if(CollectionUtils.isEmpty(bean.getColumnProperyMappingList())){
			return Collections.emptyList();
		}
		return doGenerateFields(bean.getColumnProperyMappingList());
	}
	
	
	protected abstract List<String> doGenerateFields( List<FieldGenerateModel> columnProperyMappingList);
	
	
	
	@Override
	protected List<String> generateMethods(BeanGenerateModel bean) {
		if(CollectionUtils.isEmpty(bean.getColumnProperyMappingList())){
			return Collections.emptyList();
		}
		return doGenerateMethods(bean.getColumnProperyMappingList());
	}
	
	
	protected abstract List<String> doGenerateMethods( List<FieldGenerateModel> columnProperyMappingList);
	
	
	protected  List<String> generateOthers(BeanGenerateModel bean) {
		List<EnumGenerateModel> enumModelList = new ArrayList<EnumGenerateModel>();
		for(FieldGenerateModel item : bean.getColumnProperyMappingList()){
			if(item instanceof EnumFieldGenerateModel){
				enumModelList.add(((EnumFieldGenerateModel)item).getEnumGenerateModel());
			}
		}
		return doGenerateInnerClass(enumModelList);
	}
	
	
	
	protected abstract List<String> doGenerateInnerClass(List<EnumGenerateModel> enumModelList);
}
